package logic

import (
	"code.bydev.io/cht/customer/kyc_admin_service/internal/domain/consumer"
	"code.bydev.io/cht/customer/kyc_admin_service/service/consumer/internal/svc"
	"code.bydev.io/frameworks/byone/core/logc"
	"code.bydev.io/frameworks/byone/kafka"
	"context"
)

type ChtKycServicePublicKycActionLogic struct {
	ctx *svc.ServiceContext
}

func NewChtKycServicePublicKycActionLogic(ctx *svc.ServiceContext) *ChtKycServicePublicKycActionLogic {
	return &ChtKycServicePublicKycActionLogic{ctx: ctx}
}

func (t *ChtKycServicePublicKycActionLogic) Consume(ctx context.Context, message *kafka.Message) error {
	logc.Infow(ctx, "Byone Consume start", logc.Field("message", message))
	e := t.ctx.NothingEnv
	dm := consumer.NewDomain(
		e.SecHub(),
		e.ChtKycDB(),
		e.UserDB(),
		e.Kafka(),
		e.Logger(),
		e.Teller(),
		e.KycSecHub(),
		e.KycSvc(),
		e.InternalDataKey(),
		t.ctx.KafkaProducer,
	)
	dm.ByoneConsumer(ctx, message.Value)
	logc.Infow(ctx, "Byone Consume end", logc.Field("msg", string(message.Value)))
	return nil
}
